package com.itheima.controller;

import com.itheima.common.CommonResult;
import com.itheima.common.UserPageInfo;
import com.itheima.dto.OrderDto;
import com.itheima.service.OrderService;
import com.itheima.vo.PageOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class ClientOrederController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public CommonResult ClientSubmit(@RequestBody OrderDto orderDto) {
        boolean res = orderService.ClientSubmit(orderDto);
        if (res) {
            return CommonResult.error("提交订单失败");
        }
        return CommonResult.success("下单成功");
    }

    @GetMapping("userPage")
    public CommonResult getOrderList(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        UserPageInfo<PageOrderVo> userPageInfo = orderService.userPage(page, pageSize);
        return CommonResult.success(userPageInfo);
    }
}
